//
//  MSEditCell.m
//  SocietySale
//
//  Created by Mike on 16/11/1.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSEditCell.h"

@interface MSEditCell ()
@property (nonatomic, strong) DOImageView *icon;
@property (nonatomic, strong) GXButton *secureBtn;
@end
@implementation MSEditCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.icon = [[DOImageView alloc] initWithFrame:CGRectMake(22, 15.5, 19, 19)];
    [self.contentView addSubview:self.icon];
    
    self.inputField = [[UITextField alloc] initWithFrame:CGRectMake(51, 0, SCREEN_WIDTH - 70 ,50)];
    self.inputField.textColor = [UIColor blackColor];
    self.inputField.font = HeitiFont(14);
    self.inputField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.contentView addSubview:self.inputField];
    
    _secureBtn = [[GXButton alloc] initWithFrame:CGRectMake(SCREENWIDTH-50, 10, 30, 30)];
    _secureBtn.relayout = YES;
    _secureBtn.hidden = YES;
    _secureBtn.imageViewFrame =  CGRectMake(6, 9.5, 17, 11);
    [_secureBtn setImage:[UIImage imageNamed:@"ls_eyeclose"] forState:UIControlStateNormal];
    [_secureBtn setImage:[UIImage imageNamed:@"ls_eyeopen"] forState:UIControlStateSelected];
    [_secureBtn addTarget:self action:@selector(closeEyeClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_secureBtn];
    
    _verifyBtn = [[GXButton alloc] initWithFrame:CGRectMake(SCREENWIDTH-97, 12.5, 82, 25)];
    _verifyBtn.tag = 10;
    [_verifyBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
    [_verifyBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    _verifyBtn.titleLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:13];
    _verifyBtn.layer.borderColor = kBlueColor.CGColor;
    _verifyBtn.layer.borderWidth = 1;
    _verifyBtn.layer.masksToBounds = YES;
    _verifyBtn.layer.cornerRadius = 2.5;
    _verifyBtn.hidden = YES;
    [self.contentView addSubview:_verifyBtn];
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(12, 50, SCREEN_WIDTH-24, 0.6)];
    horizonLineView.backgroundColor = kNormalGray;
    [self.contentView addSubview:horizonLineView];
}

- (void)setData:(DOKeyValue *)data {
    _data = data;
    self.icon.imgURLStr = _data.key;
    self.inputField.placeholder = _data.placeHolder;
    self.inputField.text = _data.value;
    if ([_data.placeHolder containsString:@"密码"]) {
        self.inputField.width = SCREEN_WIDTH - 110;
        self.inputField.secureTextEntry = YES;
        _secureBtn.hidden = NO;
    }else{
        self.inputField.keyboardType = UIKeyboardTypeNumberPad;
    }
    if ([_data.placeHolder containsString:@"验证码"]) {
        self.inputField.width = SCREEN_WIDTH - 165;
    }
}

- (void)closeEyeClick:(UIButton *)eyeBtn{
    if ([_data.placeHolder containsString:@"密码"]) {
        eyeBtn.selected = !eyeBtn.selected;
        self.inputField.secureTextEntry = !eyeBtn.selected;
        [self.inputField becomeFirstResponder];
    }
}

@end
